home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pavt150.zip / CAPI.ZIP / JAMLOCK.C < prev    next >
C/C++ Source or Header  |  1993-07-01  |  2KB  |  97 lines

  1. /*
  2. **  JAM(mbp) - The Joaquim-Andrew-Mats Message Base Proposal
  3. **
  4. **  C API
  5. **
  6. **  Written by Joaquim Homrighausen.
  7. **
  8. **  ----------------------------------------------------------------------
  9. **
  10. **  jamlock.c (JAMmb)
  11. **
  12. **  Locking and unlocking of message base
  13. **
  14. **  Copyright 1993 Joaquim Homrighausen, Andrew Milner, Mats Birch, and
  15. **  Mats Wallin. ALL RIGHTS RESERVED.
  16. **
  17. **  93-06-28    JoHo
  18. **  Initial coding.
  19. */
  20. #define JAMCAPI 1
  21.  
  22. #include "jammb.h"
  23.  
  24. /*
  25. **  Locks message base and if successful, optionally reads the header info
  26. **  block at the beginning of the header file. Returns 1 upon success and
  27. **  0 upon failure.
  28. */
  29. int _JAMPROC JAMmbLockMsgBase(JAMAPIRECptr apirec, int FetchHdrInfo)
  30. {
  31.     /* Make sure it's open */
  32.     if (!apirec->isOpen)
  33.         {
  34.         apirec->APImsg=JAMAPIMSG_ISNOTOPEN;
  35.         return (0);
  36.         }
  37.  
  38.     /* Attempt to lock it if we don't already have a lock */
  39.     if (!apirec->HaveLock)
  40.         {
  41.         if (apirec->LockFunc(apirec, 1)<0)
  42.             {
  43.             apirec->APImsg=JAMAPIMSG_CANTLKFILE;
  44.             return (0);
  45.             }
  46.         /* Make sure we know about the lock */
  47.         apirec->HaveLock=1;
  48.         }
  49.  
  50.     /* Read header info block if told to */
  51.     if (FetchHdrInfo)
  52.         {
  53.         if (!JAMmbUpdateHeaderInfo(apirec, 0))
  54.             return (0);
  55.         }
  56.  
  57.     apirec->APImsg=JAMAPIMSG_NOTHING;
  58.     return (1);
  59. }
  60.  
  61. /*
  62. **  Unlocks message base and if successful, optionally updates the header
  63. **  info block (and its ModCounter) at the beginning of the header file.
  64. **  Returns 1 upon success and 0 upon failure.
  65. */
  66. int _JAMPROC JAMmbUnLockMsgBase(JAMAPIRECptr apirec, int UpdateHdrInfo)
  67. {
  68.     /* Make sure it's open */
  69.     if (!apirec->isOpen)
  70.         {
  71.         apirec->APImsg=JAMAPIMSG_ISNOTOPEN;
  72.         return (0);
  73.         }
  74.  
  75.     /* Make sure we have lock */
  76.     if (!apirec->HaveLock)
  77.         {
  78.         apirec->APImsg=JAMAPIMSG_ISNOTLOCKED;
  79.         return (0);
  80.         }
  81.  
  82.     /* Update header info if told to before unlocking */
  83.     if (UpdateHdrInfo)
  84.         {
  85.         if (!JAMmbUpdateHeaderInfo(apirec, 1))
  86.             return (0);
  87.         }
  88.  
  89.     /* Unlock the file */
  90.     apirec->LockFunc(apirec, 0);
  91.     apirec->HaveLock=0;
  92.     apirec->APImsg=JAMAPIMSG_NOTHING;
  93.     return (1);
  94. }
  95.  
  96. /* end of file "jamlock.c" */
  97.